package com.hspedu.poly_.test;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/23
 * @time 0:59
 */
public class Theory2 {
    public static void main(String[] args) {
        GrandPa2 grandpa = new Son2();
        System.out.println(grandpa.name);
        System.out.println(grandpa.getName());

        Father2 f = new Son2();
        System.out.println(f.name);
        System.out.println(f.getName());

        f.sleep();
    }
}

class GrandPa2 {
    String name = "大头爷爷";
    String hobby = "旅游";

    public String getName() {
        return name;
    }

}

class Father2 extends GrandPa2 {
    String name = "大头爸爸";
    int age = 39;
    public void sleep() {
        System.out.println("father sleep");
    }

    @Override
    public String getName() {
        return super.getName();
    }

}

class Son2 extends Father2 {
    String name = "大头儿子";

    @Override
    public void sleep() {
        System.out.println("son sleep");
    }

    @Override
    public String getName() {
        return name;
    }
}
